package com.sumainfor.wx.system.epc.controller;

import com.sumainfor.common.util.FieldCheckUtil;
import com.sumainfor.common.util.JsonResult;
import com.sumainfor.wx.system.epc.service.CommodityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * 功能描述:
 *
 * @Auther: zhlu
 * @Date: 2019/6/12 20:41
 * @Description:
 */
@RestController
@RequestMapping("/comm")
public class CommodityController {

    @Autowired
    CommodityService CommodityService;

    /**
     * 功能描述:
     * 根据商品类型查询商品的名称和编号
     * @Author zhlu
     * @Description //TODO
     * @Date 2019/6/12 14:19
     */
    @GetMapping("/getCommodityByComType")
    public JsonResult getCommodityByComType(@RequestParam Map<String,Object> params){
        if(!FieldCheckUtil.isMapFieldNotNull(params,new String[]{"ComType"})){
            return  JsonResult.error("ComType不能为空！");
        }
        return JsonResult.success(CommodityService.getCommodityByComType(params));
    }

    /**
     * 功能描述:
     * 根据商品编号查询商品对应的规格名称和编号
     * @Author zhlu
     * @Description //TODO
     * @Date 2019/6/12 14:19
     */
    @GetMapping("/getCommoditySpeByComId")
    public JsonResult getCommoditySpeByComId(@RequestParam Map<String,Object> params){
        if(!FieldCheckUtil.isMapFieldNotNull(params,new String[]{"ComId"})){
            return  JsonResult.error("ComId不能为空！");
        }
        return JsonResult.success(CommodityService.getCommoditySpeByComId(params));
    }

    /**
     * 功能描述:
     * 根据规格编号查询对应的型号和单位
     * @Author zhlu
     * @Description //TODO
     * @Date 2019/6/12 14:19
     */
    @GetMapping("/getCommoditySpeMoByComSpeId")
    public JsonResult getCommoditySpeMoByComSpeId(@RequestParam Map<String,Object> params){
        if(!FieldCheckUtil.isMapFieldNotNull(params,new String[]{"ComSpeId"})){
            return  JsonResult.error("ComSpeId不能为空！");
        }
        return JsonResult.success(CommodityService.getCommoditySpeMoByComSpeId(params));
    }

}
